package com.kingdee.pda.ui.sn_query_edit;

import android.content.Context;

import com.example.basecommon.http.MyObserver;
import com.example.basecommon.http.RxHelper;
import com.example.basecommon.http.rxjava.BaseResponse;
import com.example.basecommon.http.rxjava.HttpUtils;
import com.example.basecommon.utils.ConstantUtil;
import com.example.basecommon.utils.SpeakUtils;
import com.kingdee.pda.Api;
import com.kingdee.pda.entity.Warehouse;

import java.util.HashMap;
import java.util.List;

/**
 * @author：dlj
 * @data：2021/12/10
 * @des：
 */
public class SnQueryPresenter implements SnQueryContract.ISnQueryPresenter {
    private Context context;
    private SnQueryContract.ISnQueryView view;

    public SnQueryPresenter(Context context, SnQueryContract.ISnQueryView view) {
        this.context = context;
        this.view = view;
    }


    @Override
    public void getOrgList() {
        HashMap<String, Object> map = new HashMap<>();
        MyObserver<List<Warehouse>> myObserver = new MyObserver<List<Warehouse>>(context) {
            @Override
            public void onSuccess(BaseResponse<List<Warehouse>> result) {
              view.getOrgListSuccess(result.data);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                SpeakUtils.speakWithToast(context, msg, false, false);
            }
        };
        HttpUtils.request(Api.class)
                .getWarehouseList(ConstantUtil.GET_ORG_LIST, map)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }

    @Override
    public void pdaSnQuery(HashMap<String, Object> map) {
        MyObserver<List<ItemSNInfoVo>> myObserver = new MyObserver<List<ItemSNInfoVo>>(context) {
            @Override
            public void onSuccess(BaseResponse<List<ItemSNInfoVo>> result) {
                view.pdaSnQuerySuccess(result.data);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                SpeakUtils.speakWithToast(context, msg, false, false);
            }
        };
        HttpUtils.request(Api.class)
                .pdaQuerySnInfo(ConstantUtil.PDA_SN_QUERY, map)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }
}



